package SortAlgorithmPractice;

import java.util.Arrays;

public class ShellSort {
    public static void main(String[] args) {
        int[] arr = {3,1,5,6,9,7,8,10};
        System.out.printf("Sort before : %s\n", Arrays.toString(arr));
        ShellSort(arr);
        System.out.printf("Sort after : %s\n", Arrays.toString(arr));
    }

    public static void ShellSort(int[] arr) {
        for (int gap = arr.length/2; gap > 0; gap/=2 ) {
            for (int i = gap; i < arr.length; i++) {
                int temp = arr[i];
                int j;
                for (j = i; j >= gap && arr[j - gap] > temp ; j -= gap) {
                    arr[j] = arr[j - gap];
                }
                arr[j] = temp;
            }
        }
    }
}
